package com.xch.sboot.config.login;

import com.xch.sboot.service.common.RedisDataService;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import javax.annotation.Resource;

/**
 * @author xch
 * 2022/12/30 14:22
 */
@Configuration
public class WebAppConfig implements WebMvcConfigurer {

    @Resource
    private RedisDataService redisDataService;

    @Resource
    private LoginProperties loginProperties;

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(new LoginInterceptor(redisDataService, loginProperties)).addPathPatterns("/**")
                //排除swagger相关的路径
                .excludePathPatterns("/swagger-ui.html")
                .excludePathPatterns("/configuration/ui")
                .excludePathPatterns("/swagger-resources/**")
                .excludePathPatterns("/configuration/security")
                .excludePathPatterns("/v2/api-docs")
                .excludePathPatterns("/error")
                .excludePathPatterns("/webjars/**")
                .excludePathPatterns("/**/favicon.ico")
        ;
    }
}
